import React from 'react';
import {
    Row,
    Col,
    Table,
    Form,
} from 'antd';
import axios from 'axios';
import intercept from '../../../utils/intercept';
import { config } from 'utils';
import { Input } from 'antd';
import format from '../RentAdmin/format';
import '../less/CustomLine.less';

class CheckRecord extends React.Component {
    constructor(props) {
        super(props);
        const user = JSON.parse(sessionStorage.getItem("user"));
        this.state = {
            dataSource: [],
            loading: true,
            pagination: {
                current: 1,
                pageSize: 10
            },
            onChange: this.onChange,
            keyword: '',
            user: user
        };
    };

    componentDidMount() {
        this.getBalance();

    };

    search(value) {
        this.setState({ keyword: value });
        this.getBalance({ keyword: value });
    }

    onChange = (pagination, filters, sorter) => {
        this.getBalance({
            sortField: sorter.field,
            sortOrder: sorter.order,
            page: pagination.current,
            keyword: this.state.keyword,
            ...filters
        });
    };

    getBalance = (params = {}) => {
        const token = sessionStorage.getItem("token");
        var keyword = typeof (params.keyword) === "undefined"
            ? ''
            : params.keyword;
        this.setState({ loading: true });
        axios.get(`${config.api}CustomLine/GetCustomlineCheckRecord?page=${params.page}&pageSize=${this.state.pagination.pageSize}&keyword=${keyword}`, { headers: { Authorization: 'Bearer ' + token } }).then((data) => {
            if (data.data.result) {
                const pagination = {
                    ...this.state.pagination
                };
                pagination.total = data.data.pageList.totalRows;
                pagination.current = params.page;
                this.setState({ loading: false, dataSource: data.data.pageList.collections, pagination });
            }
        })
        .catch(err => {
            intercept;
        });
    }


    render() {
        const Search = Input.Search;
        const columns = [
            {
                title: "订单号",
                dataIndex: "orderCode",
                width: 100
            }, {
                title: "司机姓名",
                dataIndex: "driverName",
                width: 100
            }, {
                title: "发车时间",
                dataIndex: "startDate",
                width: 100,
                render: (text, record) => {
                    return (
                        <span>{format.format(record.startDate)}</span>
                    )
                }
            }, {
                title: "金额",
                dataIndex: "refundChannel",
                width: 100,
            }, {
                title: "上车点",
                dataIndex: "upPointName",
                width: 100,
            }, {
                title: "下车点",
                dataIndex: "downPointName",
                width: 100,
            }, {
                title: "检票时间",
                dataIndex: "checkTicketTime",
                width: 100,
                render: (text, record) => {
                    return (
                        <span>{format.format(record.checkTicketTime)}</span>
                    )
                }
            }, {
                title: '操作',
                width: 100,
                dataIndex: "refundStatus"
            }
        ];
        const className = "components-table-demo-nested";
        const scroll = {
            y: 600
        };
        return (
            <div>
                <div className="searchCenter">
                    <Search
                        placeholder="请输入订单号"
                        style={{
                            width: 600
                        }}
                        onSearch={value => this.search(value)} />
                </div>
                <Row gutter={8}>
                    <Col span={24}>

                        <Table
                            className="menuItem"
                            {...this.state}
                            style={{ background: 'white' }}
                            rowKey={record => record.id}
                            bordered={true}
                            className={className}
                            columns={columns}
                            scroll={scroll} />
                    </Col>
                </Row>
            </div>
        )
    }
}
const CRecord = Form.create()(CheckRecord);
export default CRecord
